﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using DLTN.Entities;
using DLTN.Data;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class Admin_Tour_TTChiTietDatTour : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!Page.IsPostBack)
        {

            if (Request.QueryString["id"] != null)
            {
                try
                {
                    H_CatalogId.Value = Request.QueryString["id"].ToString();
                    using (TList<ChiTietDatTour> TList_ChiTietDatTour = DataRepository.ChiTietDatTourProvider.GetByIdBooking(H_CatalogId.Value))
                    {
                        if (TList_ChiTietDatTour.Count > 0)
                        {
                            lbTenCongTy.Text = GetTenCongTy(TList_ChiTietDatTour[0].IdBooking);
                            lbHoTen.Text = GetHoTen(TList_ChiTietDatTour[0].IdBooking);
                            lbDienThoai.Text = GetDienThoai(TList_ChiTietDatTour[0].IdBooking);
                            lbEmail.Text = GetEmail(TList_ChiTietDatTour[0].IdBooking);
                            lbMaSoThue.Text = GetMaSoThue(TList_ChiTietDatTour[0].IdBooking);
                            lbDiaChi.Text = GetDiaChi(TList_ChiTietDatTour[0].IdBooking);
                            lbDiDong.Text = GetDiDong(TList_ChiTietDatTour[0].IdBooking);
                            lbNgayCapNhat.Text = GetNgayCapNhat(TList_ChiTietDatTour[0].IdBooking).ToString("dd/MM/yyyy");
                            string query;
                            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["netTiersConnectionString"].ConnectionString);
                            conn.Open();
                            query = "UPDATE TourDat SET TrangThai = 1 where Id = '" + Request.QueryString["Id"].ToString() + "'";
                            SqlCommand sqlCommand = new SqlCommand();
                            sqlCommand.Connection = conn;
                            sqlCommand.CommandText = query;
                            sqlCommand.ExecuteNonQuery();
                            conn.Close();
                        }
                    }

                    Pager1.CurrentIndex = 1;
                    Bind_Data(Pager1.CurrentIndex);


                }
                catch (Exception ex)
                {
                    Common.WriteLog("TTChiTietDatTour.aspx.cs", "Page_Load()", ex.ToString());
                    string strScript = "<script>parent.parent.GB_hide();</script>";
                    this.RegisterClientScriptBlock("strScript", strScript);
                }
            }
        }
    }

    protected void Bind_Data(int PageNo)
    {
        int TotalRows = 0;
        string WhereClause = "1=1 ";
        WhereClause += String.Format(" AND IdBooking like N'%{0}%'", H_CatalogId.Value);
        using (DataSet dsChiTietDatTour = DataRepository.Provider.ExecuteDataSet("ChiTietDatTour_GetPaged", WhereClause, "Id DESC", PageNo - 1, Pager1.PageSize))
        {
            gridcatalog.DataSource = dsChiTietDatTour.Tables[0];
            gridcatalog.DataBind();
            try
            {
                TotalRows = Convert.ToInt32(dsChiTietDatTour.Tables[1].Rows[0][0]);
            }
            catch (Exception)
            {
            }
        }

        Pager1.ItemCount = TotalRows;
        if (TotalRows <= Pager1.PageSize)
            Pager1.Visible = false;
        else
            Pager1.Visible = true;
    }

    protected void Pager1_Command(object sender, CommandEventArgs e)
    {
        try
        {
            int currnetPageIndex = Convert.ToInt32(e.CommandArgument);
            Pager1.CurrentIndex = currnetPageIndex;
            Bind_Data(currnetPageIndex);
        }
        catch (Exception ex)
        {
            Common.WriteLog("TTChiTietDatTour.aspx.cs", "Pager1_Command()", ex.ToString());
        }
    }
    public string GetTenCongTy(object Id)
    {
        string s = Id.ToString();
        TourDat ent_TourDat = DataRepository.TourDatProvider.GetById(s);
        return ent_TourDat.TenCongTy;
    }
    public string GetHoTen(object Id)
    {
        string s = Id.ToString();
        TourDat ent_TourDat = DataRepository.TourDatProvider.GetById(s);
        return ent_TourDat.HoTen;
    }
    public string GetDienThoai(object Id)
    {
        string s = Id.ToString();
        TourDat ent_TourDat = DataRepository.TourDatProvider.GetById(s);
        return ent_TourDat.DienThoai;
    }
    public string GetEmail(object Id)
    {
        string s = Id.ToString();
        TourDat ent_TourDat = DataRepository.TourDatProvider.GetById(s);
        return ent_TourDat.ThuDienTu;
    }
    public string GetMaSoThue(object Id)
    {
        string s = Id.ToString();
        TourDat ent_TourDat = DataRepository.TourDatProvider.GetById(s);
        return ent_TourDat.MaSoThue;
    }
    public string GetDiaChi(object Id)
    {
        string s = Id.ToString();
        TourDat ent_TourDat = DataRepository.TourDatProvider.GetById(s);
        return ent_TourDat.DiaChi;
    }
    public string GetDiDong(object Id)
    {
        string s = Id.ToString();
        TourDat ent_TourDat = DataRepository.TourDatProvider.GetById(s);
        return ent_TourDat.DiDong;
    }
    public string GetDoTuoi(object Id)
    {
        int s = Convert.ToInt32(Id.ToString());
        LoaiTuoi ent_LoaiTuoi = DataRepository.LoaiTuoiProvider.GetById(s);
        return ent_LoaiTuoi.DoTuoi;
    }
    public string GetGioiTinh(object Id)
    {
        int s = Convert.ToInt32(Id.ToString());
        GioiTinh ent_GioiTinh = DataRepository.GioiTinhProvider.GetById(s);
        return ent_GioiTinh.GioiTinh;
    }
    public string GetLoaiKhach(object Id)
    {
        int s = Convert.ToInt32(Id.ToString());
        LoaiKhach ent_LoaiKhach = DataRepository.LoaiKhachProvider.GetById(s);
        return ent_LoaiKhach.TenLoaiKhach;
    }
    public DateTime GetNgayCapNhat(object Id)
    {
        string s = Id.ToString();
        TourDat ent_TourDat = DataRepository.TourDatProvider.GetById(s);
        return ent_TourDat.NgayCapNhat;
    }
}